package ligne2vie.topos.server.service;

import ligne2vie.topos.client.service.UserService;
import ligne2vie.topos.shared.bo.TGoogleUser;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * Implementation of {@link UserService}.
 * 
 * @author thuguerre
 * @since 1.0.0
 */
public class UserServiceImpl extends RemoteServiceServlet implements UserService {

	/**
	 * Default serial UID.
	 */
	private static final long serialVersionUID = 3652627770844576590L;

	/**
	 * The Google User Service to use to manage users.
	 */
	private final static com.google.appengine.api.users.UserService userService = UserServiceFactory.getUserService();

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String createLoginURL(String destinationURL) {
		return userService.createLoginURL(destinationURL);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String createLoginURL(String destinationURL, String authDomain) {
		return userService.createLoginURL(destinationURL, authDomain);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String createLogoutURL(String destinationURL) {
		return userService.createLogoutURL(destinationURL);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String createLogoutURL(String destinationURL, String authDomain) {
		return userService.createLogoutURL(destinationURL, authDomain);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public TGoogleUser getCurrentUser() {

		User googleUser = userService.getCurrentUser();

		return new TGoogleUser(googleUser.getAuthDomain(), googleUser.getEmail(), googleUser.getNickname(),
				googleUser.getUserId());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean isUserAdmin() {
		return userService.isUserAdmin();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean isUserLoggedIn() {
		return userService.isUserLoggedIn();
	}

}
